import { Token } from '@/types/data'
import { LoginAction } from '@/types/store'
import { getToken } from '@/utils/storage'

/* eslint-disable camelcase */

const initialState:Token = getToken()

const login = (state:Token = initialState, action: LoginAction) => {
  if (action.type === 'login/token') {
    return action.payload
  } else if (action.type === 'login/logout') {
    return { refresh_token: '', token: '' }
  }
  return state
}

export default login
